package com.imooc.aop.schema.advice;

import org.aspectj.lang.ProceedingJoinPoint;

public class MoocAspect {
	
	public void before() {
		System.out.println("MoocAspect before.");
	}
	
	public void afterReturning() {
		System.out.println("MoocAspect afterReturning.");
	}
	
	public void afterThrowing() {
		System.out.println("MoocAspect afterThrowing.");
	}
	
	public void after() {
		System.out.println("MoocAspect after.");
	}
	
	//环绕通知 第一个参数必须是ProceedingJoinPoint类型
	public Object around(ProceedingJoinPoint pjp) {
		Object obj = null;
		try {
			//业务执行前触发的操作
			System.out.println("MoocAspect around 1.");
			
			//下面是固定写法，意思是具体执行业务的操作
			obj = pjp.proceed();
			
			//业务执行后触发的操作
			System.out.println("MoocAspect around 2.");
		} catch (Throwable e) {
			e.printStackTrace();
		}
		//必须返回
		return obj;
	}
	
	//带参数的环绕通知 参数类型和名字必须要和业务方法的类型名字一致，否则报错
	public Object aroundInit(ProceedingJoinPoint pjp, String bizName, int times) {
		System.out.println(bizName + "   " + times);
		Object obj = null;
		try {
			System.out.println("MoocAspect aroundInit 1.");
			obj = pjp.proceed();
			System.out.println("MoocAspect aroundInit 2.");
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return obj;
	}
	
}
